use salvo::{handler, prelude::StatusCode, writing::Json, Depot, FlowCtrl, Request, Response};

#[handler]
pub async fn handle_40x(&self, _req: &Request, _depot: &Depot, res: &mut Response, ctrl: &mut FlowCtrl) {
    match res.status_code {
        Some(StatusCode::NOT_FOUND) => {
            res.render(Json("404 not found"));
            ctrl.skip_rest();
        },
        Some(StatusCode::BAD_REQUEST) => {
            res.render(Json("400 bad request"));
            ctrl.skip_rest();
        },
        Some(StatusCode::METHOD_NOT_ALLOWED) => {
            res.render(Json("405 method not allowed"));
            ctrl.skip_rest();
        }
        _ => {}
    }
}
